'''MainWindow'''
import sys

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtCore import QTimer
from PyQt5.QtGui import QImage, QPixmap, QKeyEvent
from PyQt5.QtWidgets import QMessageBox,QInputDialog
from PyQt5.QtCore import Qt
from fatigue_algo.scrfd import scrfd
from fatigue_algo.landmark_mbv2.onnx.detector import Detector

from GUI.login import Ui_Login_MainWindow

from calibrate_window import CalibrateWindow
from detect_window import DetectWindow

'''登录窗口'''
class LoginWindow(QtWidgets.QMainWindow, Ui_Login_MainWindow):

    def __init__(self):
        super(LoginWindow,self).__init__()
        self.setupUi(self)  # 创建窗体对象
        self.init()  #按钮事件绑定
        self.scrfd_detector = scrfd.SCRFD("scrfd_500m_kps.onnx")  # 人脸检测模型
        self.landmark_detector = Detector()

    #为按钮绑定enter槽函数
    def init(self):
        self.pushButton.clicked.connect(lambda : self.enter())

    #进入疲劳检测系统
    def enter(self):
        calibrateWindow = CalibrateWindow(self.scrfd_detector,self.landmark_detector)
        calibrateWindow.show()  # 跳转至校准页面
        self.close()  # 关掉当前页面
        calibrateWindow.open_camera()  #打开摄像头

if __name__ == '__main__':
    from PyQt5 import QtCore
    QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)#自适应分辨率

    app = QtWidgets.QApplication(sys.argv)
    window = LoginWindow()
    window.show()

    sys.exit(app.exec_())